package com.movie.ticket.sale.authorassembly.dao;

import com.movie.ticket.sale.moviecommon.model.TManager;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Ticket
 * @since 2020-12-08
 */
public interface TManagerMapper extends BaseMapper<TManager> {

    @Select("select * from t_manager where name=#{userName}")
    List<TManager> checkNameIsBeUsed(String userName);

    @Select("select * from t_manager where tel=#{tel}")
    List<TManager> checkTelIsBeUsed(String tel);

    @Insert("insert into t_manager(role,password,name,tel) values(#{role},#{password},#{name},#{tel})")
    void addANewManager(TManager manager);

    @Select("select * from t_manager where name=#{name} limit 0,1")
    TManager findByName(String name);

    @Select("select * from t_manager where tel=#{tel} limit 0,1")
    TManager findByTel(String tel);

    @Select("select ifnull(id,0) from\n" +
            "(select t1.id,t1.role,t1.tel from t_cinema as t1\n" +
            "union select t2.id,t2.role,t2.tel from t_user as t2) as t3\n" +
            "where t3.role=#{role} and t3.tel=#{tel}")
    int getIdFromRoleAndTel(@Param("role") Integer role, @Param("tel") String tel);
}
